package cn.jingyuan.bee.utils.text;

/**
 * ASCII 字符对应的字符串缓存
 */
public class ASCIIStringCache {

    private static final int ASCII_LENGTH = 128;

    private static final String[] CACHE = new String[ASCII_LENGTH];

    static {
        for (char c = 0; c < ASCII_LENGTH; c++) {
            CACHE[c] = String.valueOf(c);
        }
    }

    /**
     * 字符转为字符串<br>
     * 如果为 ASCII 字符，使用缓存
     *
     * @param c 字符
     *
     * @return 字符串
     */
    public static String toString(char c) {
        return c < ASCII_LENGTH ? CACHE[c] : String.valueOf(c);
    }

}
